<template>
  <div>
    <div class="toolbar">
      <el-button type="primary" @click="showDetail('create')">新增</el-button>
    </div>
    <el-table :data="organizations" v-loading="loading">
      <el-table-column prop="orgCode" label="组织网点代码" width="150"></el-table-column>
      <el-table-column prop="orgName" label="组织网点名称"></el-table-column>
      <el-table-column prop="contact" label="联系人" width="150"></el-table-column>
      <el-table-column prop="telephone" label="联系电话" width="150"></el-table-column>
      <el-table-column prop="isdeleted" width="100" label="状态">
        <template scope="scope">
          <el-tag
            :type="scope.row.isdeleted === '1' ? 'success' : 'gray'"
            close-transition>{{scope.row.isdeleted === '1' ? '在用' : '停用'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120" inline-template align="center">
        <el-button type="text" size="small" @click="showDetail(row.pkid)">查看详情</el-button>
      </el-table-column>
    </el-table>
    <el-pagination class="page"
      @current-change="handleCurrentChange"
      :current-page="1"
      :page-size="10"
      layout="total, prev, pager, next, jumper"
      :total="page.totalRecord">
    </el-pagination>
  </div>
</template>
<style scoped>
  .page{
    text-align: right;
    margin: 10px 0px;
  }
</style>
<style>
  .toolbar{
    padding: 10px;
  }
</style>
<script>
  import organizationApi from '../../../api/crm/organizationApi'

  export default {
    data () {
      return {
        organizations: [],
        page: {},
        loading: false,
        customerId: ''
      }
    },
    created () {
      this.loading = true
      this.customerId = this.$route.params.customerid
      organizationApi.queryOrgByPage(1, 10, this.customerId).then(resp => {
        this.organizations = resp.body.data
        this.page = resp.body.page
        this.loading = false
      })
    },
    methods: {
      handleCurrentChange: function (pageNo) {
        this.loading = true
        organizationApi.queryOrgByPage(pageNo, 10, this.customerId).then(resp => {
          this.customers = resp.body.data
          this.page = resp.body.page
          this.loading = false
        })
      },
      showDetail: function (id) {
        this.$router.push({name: 'organizationDetail', params: {id: id, customerid: this.customerId}})
      }
    }
  }
</script>